import java.util.Arrays;
import java.util.Random;

public class TestSort {

//    //生成的数据是从小到大
    public static void order(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i]=i;
        }
    }
    //生成的数据是从大到小
    public static void notOrder(int[]array){
        for (int i = 0; i < array.length; i++) {
            array[i]=array.length-i;
        }
    }
    //生成的数据是随机的
    public static void random(int[]array){
        Random random=new Random();
        for (int i = 0; i < array.length; i++) {
            array[i]=random.nextInt(10_0000);
        }
    }
    public static void testInsertOrder(int[]array){
        int[]array2=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.insertSort(array2);
       long endTime=System.currentTimeMillis();
        System.out.println("直接插入排序所用的时间是："+(endTime-startTime));
    }
    public static void testShellOrder(int[]array){
        int[]array2=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.shellSort(array2);
        long endTime=System.currentTimeMillis();
        System.out.println("希尔排序所用的时间是："+(endTime-startTime));
    }
    public static void testHeapOrder(int[]array){
        int[]array2=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.heapSort(array2);
        long endTime=System.currentTimeMillis();
        System.out.println("堆排序所用的时间是："+(endTime-startTime));
    }
    public static void testSelectOrder(int[]array){
        int[]array2=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.selectSort(array2);
        long endTime=System.currentTimeMillis();
        System.out.println("选择排序所用的时间是："+(endTime-startTime));
    }
    public static void testBubbleOrder(int[]array){
        int[]array2=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.bubbleSort(array2);
        long endTime=System.currentTimeMillis();
        System.out.println("冒泡排序所用的时间是："+(endTime-startTime));
    }
    public static void testQuickOrder(int[]array){
        int[]array2=Arrays.copyOf(array,array.length);
        long startTime=System.currentTimeMillis();
        Sort.quickSort(array2);
        long endTime=System.currentTimeMillis();
        System.out.println("快速排序所用的时间是："+(endTime-startTime));
    }
    public static void main2(String[] args) {
        int[]array=new int[10_0000];
        //order(array);
        notOrder(array);
        //random(array);
        testInsertOrder(array);
        testShellOrder(array);
        testHeapOrder(array);
        testSelectOrder(array);
        testBubbleOrder(array);
        testQuickOrder(array);
    }
    public static void main(String[] args) {
        int[] array={27,15,3,14,29,2};
//        Sort.shellSort(array);
//        Sort.insertSort(array);
//        Sort.heapSort(array);
//        Sort.selectSort(array);
//       Sort.bubbleSort(array);
        Sort.quickSort(array);
        //Sort.mergeSort(array);
//        Sort.mergeSortNor(array);
        System.out.println(Arrays.toString(array));
    }
}
